package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: atp
 * Date: 2022-11-01
 * Time: 17:33
 */
public class AddOperation implements IOOperation {

    public void work(BookList bookList) {
        System.out.println("添加图书");
        System.out.println("请输入你要增加的书名: ");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        System.out.println("请输入你要增加的图书的作者: ");
        String author = scanner.nextLine();

        System.out.println("请输入你要增加的图书的价格: ");
        int price = scanner.nextInt();
        scanner.nextLine();

        System.out.println("请输入你要增加的图书的类型: ");
        String type = scanner.nextLine();

        Book book = new Book(name,author,price,type);
        //获取当前可以存放书的位置
        int currentSize = bookList.getUseSize();
        //把书放入指定位置
        bookList.setBooks(book,currentSize);
        //书的数量+1
        bookList.setUseSize(currentSize + 1);
    }
}
